<?php


namespace App\Transformers\Store;


use App\Models\StoreBargain;
use App\Models\StoreBargainUser;
use App\Transformers\Product\ProductTransformer;
use App\Transformers\SystemNotice\SystemStoreTransformer;
use App\Transformers\User\UserTransformer;
use League\Fractal\TransformerAbstract;

class StoreBargainTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['product','systemStore','storeBargainUser'];

    public function transform(StoreBargain $data)
    {
        return [
            'id' => $data->id,
            'product_id' =>$data->product_id ?? "",
            'bargain_user_id' =>$data->bargain_user_id ?? "",
            'shop_id' =>$data->shop_id ?? "",
            'title' =>$data->title ?? "",
            'pic' =>$data->pic ?? "",
            'pic_url' => $data->pic ?? 'https://placeimg.com/640/480/any',
            'price' =>$data->price ?? "",
            'min_price' =>$data->min_price ?? "",
            'participants' =>$data->participants ?? "",
            'buyers' =>$data->buyers ?? "",
            'quota' =>$data->quota ?? "",
            'quota_show' =>$data->quota_show ?? "",
            'stop_at' =>$data->stop_at ?? "",
            'start_at' =>$data->start_at ?? "",
            'store_name' =>$data->store_name ?? "",
            'rotation_chart' =>$data->rotation_chart ?? "",
            'rotation_chart_url' => $data->rotation_chart ?? 'https://placeimg.com/640/480/any',
            'unit_name' =>$data->unit_name ?? "",
            'bargain_max_price' =>$data->bargain_max_price ?? "",
            'bargain_min_price' =>$data->bargain_min_price ?? "",
            'desc' =>$data->desc ?? "",
            'introduction' =>$data->introduction ?? "",
            'temp_id' =>$data->temp_id ?? "",
            'rule' =>$data->rule ?? "",
            'stock' =>$data->stock ?? "",
            'sales' =>$data->sales ?? "",
            'give_integral' =>$data->give_integral ?? "",
            'num' =>$data->num ?? "",
            'sort' =>$data->sort ?? "",
            'look' =>$data->look ?? "",
            'share' =>$data->share ?? "",
            'people_num' =>$data->people_num ?? "",
            'weight' =>$data->weight ?? "",
            'volume' =>$data->volume ?? "",
            'postage' =>$data->postage ?? "",
            'cost_price' =>$data->cost_price ?? "",
            'is_recommend' =>$data->is_recommend ?? 0,
            'is_postage' =>$data->is_postage ?? 0,
            'status' =>$data->status ?? 0,
            'active_status' => $data->activeStatusEnum[$data->active_status]?? "",
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
            'att_r' => $data->att_r ?? '',
        ];
    }



    /**
     *额外包含商品数据
     */

    public function includeProduct(StoreBargain $StoreBargain)
    {
        return $this->item($StoreBargain->product, new ProductTransformer());
    }

    /**
     *额外包含砍价用户数据
     */

    public function includeStoreBargainUser(StoreBargain $StoreBargain)
    {
        return $this->item($StoreBargain->storeBargainUser, new StoreBargainUserTransformer());
    }

    /**
     *额外包含店铺数据
     */

    public function includeSystemStore(StoreBargain $StoreBargain)
    {
        return $this->item($StoreBargain->systemStore, new SystemStoreTransformer());
    }
}
